<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Companies extends CI_Controller {
    public function __construct(){
		parent::__construct();
		$this->output->nocache();
		$this -> form_validation -> set_error_delimiters('<p class="help-block danger">', '</p>');
	}
    public function profile(){
        $data['title'] = "Company Profile";
        $data['locations'] = $this->model_globals->select_all('job_locations');
        $categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
        $data['post_record'] = $this->model_jobs->count_all_jobs(NULL);
        $uri = $this->uri->segment(3);
        $employerId = $this->model_globals->select_string('employers','employer_id',array('token_key' => $uri));
        if($employerId==NULL){
           redirect('error/error-404'); 
        }else{
            $data['company_profile'] = $this->model_jobs->list_company_info($employerId)->result();
            $data['company_jobs'] = $this->model_jobs->list_job_by_employer($employerId);
        }
        $data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }
	public function get_job_category_options($categories){
		$option='';
		foreach ($categories as $category) {
			$category_id = $category -> job_category_id;
			$name = $category -> name;
			//$option .= '<optgroup label="' . $name . '">';
			$option .= '<option value="' . $category_id . '-0 "style="color:#3C8DBC;">' . $name . '</option>';
			$sub_categories = $this -> model_globals -> select_where('job_sub_categories', array('using_job_category_id' => $category_id)) -> result();
			foreach ($sub_categories as $sub_category) {
				$sub_category_id = $sub_category -> job_sub_category_id;
				$sub_name = $sub_category -> name;
				$option .= '<option value="' . $category_id . '-' . $sub_category_id . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $sub_name . '</option>';
			}
			//$option .= '</optgroup>';
		}
		return $option;
		
	}
}
